<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-add" lay-event="add">办理业务</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-add" lay-event="chakan">查看当前流程图</a>
        </script>

    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/common.js"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: webUrl+'/task/listTask?userId='+window.localStorage.getItem("userId"),
            toolbar: '#toolbarDemo',
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            skin: 'line',
            page:true,
            cols: [[
                {field:'zizeng',  title: '序号',width: 80,align:'center',templet:function (d) {
                        return d.LAY_TABLE_INDEX+1;
                    }},
                {field: 'id', width: 180, title: '任务ID',align:'center'},
                {field: 'modelName', width: 180, title: '流程', sort: true,align:'center'},
                {field: 'name', width: 180, title: '环节', sort: true,align:'center'},
                {field: 'createTime', width: 180, title: '到达时间', sort: true,align:'center',templet:function (d) {
                        return showTime(d.createTime);
                    }},
                {field: 'userName', width: 180, title: '审批人', sort: true,align:'center'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
        });

        //监听单元格事件
        table.on('tool(currentTableFilter)', function(obj){
            switch (obj.event) {
                case 'add':
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        url: webUrl + '/task/getProcessInstanceKey', //url
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify({
                            'procdef_id': obj.data.procdef_id
                        }),
                        success: function(result) {
                            if (result.data.success == true) {
                                layer.open({
                                    type: 2,
                                    title:'办理任务',
                                    area:['100%','100%'],
                                    content: '../page/table/apply.html?processInstanceKey='+result.data.processInstanceKey+'&taskId='+obj.data.id+'&processInstanceId='+obj.data.processInstanceId
                                });
                            }
                        },
                        error: function() {
                            layer.msg("操作失败");
                        }

                    });
                    break;
                case 'chakan':
                    var index = layer.open({
                        title: '查看当前流程图',
                        type: 2,
                        area: ['1100px', '600px'],
                        content: '../page/table/currentView.html?taskId='+obj.data.id+'&flag=1'
                    });
                    break;
            }

        });
    });


    //时间转换函数
    function showTime(tempDate)
    {
        var d = new Date(tempDate);
        var year = d.getFullYear();
        var month = d.getMonth();
        month++;
        var day = d.getDate();
        var hours = d.getHours();

        var minutes = d.getMinutes();
        var seconds = d.getSeconds();
        month = month<10 ? "0"+month:month;
        day = day<10 ? "0"+day:day;
        hours = hours<10 ? "0"+hours:hours;
        minutes = minutes<10 ? "0"+minutes:minutes;
        seconds = seconds<10 ? "0"+seconds:seconds;


        var time = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
        return time;
    }
</script>
</body>
</html>